package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.entity.MenuInfo;
import com.ala4.oxcafe.service.MenuInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单信息controller
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/12 14:20
 */
@RestController
@RequestMapping("/menu-info")
@AllArgsConstructor
@Tag(name = "菜单管理", description = "用于管理菜单信息")
public class MenuInfoController {

    private final MenuInfoService menuInfoService;

    @Operation(summary = "查询菜单列表")
    @GetMapping("/list")
    public R<List<MenuInfo>> list(MenuInfo menuInfo) {
        return R.ok(menuInfoService.menuInfoList(menuInfo));
    }

    @Operation(summary = "创建菜单")
    @PostMapping("/create")
    public R<MenuInfo> create(@RequestBody @Validated(MenuInfo.Create.class) MenuInfo menuInfo) {
        return R.ok(menuInfoService.createMenuInfo(menuInfo));
    }

    @Operation(summary = "更新菜单")
    @PutMapping("/update")
    public R<MenuInfo> update(@RequestBody @Validated(MenuInfo.Update.class) MenuInfo menuInfo) {
        return R.ok(menuInfoService.updateMenuInfo(menuInfo));
    }

    @Operation(summary = "删除菜单")
    @DeleteMapping("/delete/{menuId}")
    public R<?> delete(@PathVariable Long menuId) {
        menuInfoService.deleteMenuInfo(menuId);
        return R.ok();
    }

    @Operation(summary = "菜单详情")
    @GetMapping("/{menuId}")
    public R<MenuInfo> info(@PathVariable Long menuId) {
        return R.ok(menuInfoService.menuInfo(menuId));
    }
}
